﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimpleNotePad
{
    public partial class RegisterForm : Form
    {
        public RegisterForm()
        {
            InitializeComponent();
        }

        private void radioButtonOtherOS_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rb = (RadioButton)sender;

            if (rb.Checked)
            {
                textBoxFavoriteOS.Enabled = true;
            }
            else
            {
                textBoxFavoriteOS.Enabled = false;
            }
        }

        public string UserName
        {
            get { return textBoxName.Text; }
        }

        public string UserEmail
        {
            get{return textBoxEmail.Text;}
        }

        public string UserLevel
        {
            get { return comboBox1.Text; }
        }

        public string UserComment
        {
            get { return textBoxComment.Text; }
        }

        public string UserGender
        {
            get 
            {
                for (int i = 0; i < groupBox1.Controls.Count; i++)
                {
                    RadioButton rb = (RadioButton)groupBox1.Controls[i];
                    if (rb.Checked)
                        return rb.Text;
                }
                return "";
            }
        }

        public string FavoriteOS
        {
            get
            {
                for (int i = 0; i < groupBox2.Controls.Count; i++)
                {
                    if (groupBox2.Controls[i] is RadioButton)
                    {
                        RadioButton rb = (RadioButton)groupBox2.Controls[i];

                        if (rb.Checked)
                        {
                            if (rb.Name != radioButtonOtherOS.Name)
                            {
                                return rb.Text;
                            }
                            else 
                            {
                                return textBoxFavoriteOS.Text;
                            }
                        }
                    }
                }
                    return "";
            }
        }

        public string SendNews
        {
            get 
            {
                if (checkBoxNews.Checked)
                    return "Yes";
                else
                    return "NO";
            }
            
        }

        public string Enewspaper
        {
            get
            {
                if (checkBoxEnewspaper.Checked)
                    return "Yes";
                else
                    return "No";
            }
        }

        public string UserDOB
        {
            get
            {
                DateTime dt = monthCalendar1.SelectionStart;
                return dt.Day + "." + dt.Month + "." + dt.Year;
            }
        }

        private void textBoxName_Validating(object sender, CancelEventArgs e)
        {
            if (textBoxName.Text.Length == 0)
                errorProvider1.SetError(textBoxName, Properties.Resources.Error_NoName);
            else
                errorProvider1.SetError(textBoxName, Properties.Resources.Error_NoError);
        }

        private void textBoxEmail_Validating(object sender, 
            System.ComponentModel.CancelEventArgs e)
        {
            string _email = textBoxEmail.Text;

            if (_email.IndexOf('@') == -1 || _email.IndexOf('.') == -1)
                errorProvider1.SetError(textBoxEmail, Properties.Resources.Error_WrongEmail);
            else
                errorProvider1.SetError(textBoxEmail, Properties.Resources.Error_NoError);
        }

    }
}
